
const Koa=require('koa');

const Router=require ('@koa/router');

const app=new Koa();//实例化koa，生成app应用
const router=new Router();//实例化

const bodyParser=require('koa-bodyparser');

const session=require('koa-session');//缓存

const {
    login,
    sendCode,
    getList,
    addUser,
    del
}=require('./controller/user.');

const {
    APP_KEY,
}=require('./config');//配置文件


const {
    auth
}=require('./middleware/auth');

router.post('/api/login',login);//登录
router.get('/api/sendCode',sendCode);//获取验证码

router.get('/api/getList',getList);//获取用户列表
router.post('/api/adduser',addUser);//添加
router.delete('/api/del/:id',del);//删除
//校验token
app.use(auth);

app.keys=APP_KEY;
app.use(session(app));//加载服务端缓存
app.use(bodyParser());//解析post请求参数
app.use(router.routes());//应用级中间件加载路由

app.listen(9000,()=>{
    console.log(`service is running at http://localhost:9000`);
})